package com.iemes.controller.quality;

import java.util.List;
import java.util.Map;

import javax.inject.Inject;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.iemes.annotation.SystemLog;
import com.iemes.controller.index.BaseController;
import com.iemes.entity.AuditCategoryFormMap;
import com.iemes.entity.AuditLoggingFormMap;
import com.iemes.mapper.quality.AuditCategoryMapper;
import com.iemes.mapper.quality.QualityAuditLoggingMapper;
import com.iemes.plugin.PageView;
import com.iemes.util.Common;

@RequestMapping("/quality")
@Controller
public class AuditLoggingController extends BaseController {

	@Inject
	private QualityAuditLoggingMapper auditLoggingMapper;
	
	@Inject
	private AuditCategoryMapper auditCategoryMapper;
	
	
	@RequestMapping("auditlogging")
	private String fine(Model model){
		model.addAttribute("res", findByRes());
		List<AuditCategoryFormMap> auditCategoryFormMap=auditCategoryMapper.getAll();
		model.addAttribute("auditCategoryFormMap", auditCategoryFormMap);
		return Common.BACKGROUND_PATH + "/quality/auditlogging/auditlogging_list";
	}
	
	@ResponseBody
	@RequestMapping("auditlogging_findByPage")
	public PageView findByPage(String pageNow, String pageSize) throws Exception 
	{
		AuditLoggingFormMap auditLoggingFormMap=getFormMap(AuditLoggingFormMap.class);
		List<Map<String,Object>> auditLoggingFormMaps=auditLoggingMapper.getAuditLoggingFormMapByCondition(auditLoggingFormMap);
		for(Map<String,Object>map:auditLoggingFormMaps){
			if(map.get("state").toString().equals("0")){
				map.put("state", "待审核");
			}
			if(map.get("state").toString().equals("1")){
				map.put("state", "待确认");
			}
			if(map.get("state").toString().equals("2")){
				map.put("state", "已确认");
			}
			if(map.get("state").toString().equals("3")){
				map.put("state", "已通过");
			}
			if(map.get("state").toString().equals("4")){
				map.put("state", "未通过");
			}
			
		}
		LuogicPaging(pageNow, pageSize, auditLoggingFormMaps);
		return pageView;
	}
	
	@ResponseBody
	@RequestMapping(value="auditlogging_deleteEntity")
	@SystemLog(module="特采",methods="特采-删除")//凡需要处理业务逻辑的.都需要记录操作日志
	public String deleteEntity() throws Exception {
		AuditLoggingFormMap auditLoggingFormMap=getFormMap(AuditLoggingFormMap.class);
		String[] ids = getParaValues("ids");
		String arr=ids[0];
		String[] str=arr.split(",");
		for(int i=0;i<str.length;i++){
			auditLoggingFormMap.put("state", 4);
			auditLoggingFormMap.put("id", str[i]);
			baseMapper.editEntity(auditLoggingFormMap);
		}
		return "success";
	}
	
	
}
